﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Acms.Bll;

public class AcmsMenuItemEnumerator : IHierarchicalEnumerable
{
    public AcmsMenuItemEnumerator(AcmsMenuItem parent)
    {
        this.Parent = parent;
        this.Items = new List<AcmsMenuItem>();
    }

    public AcmsMenuItem Parent { get; private set; }
    public List<AcmsMenuItem> Items { get; private set; }

    #region IHierarchicalEnumerable Members

    public IHierarchyData GetHierarchyData(object enumeratedItem)
    {
        return (AcmsMenuItem)enumeratedItem;
    }

    #endregion

    #region IEnumerable Members

    public System.Collections.IEnumerator GetEnumerator()
    {
        foreach (var item in Items)
        {
            yield return item;
        }
    }

    #endregion
}

public class AcmsMenuItem : IHierarchyData
{
    public AcmsMenuItem(int postID, string displayName, string url, string path, bool readyToPublish, bool requiresPublishing, Template.NodeTypes nodeType)
    {
        this.PostID = postID;
        this.DisplayName = displayName;
        this.Url = url;
        this.Path = path;
        this.Children = new AcmsMenuItemEnumerator(this);
        this.ReadyToPublish = readyToPublish;
        this.RequiresPublishing = requiresPublishing;
        this.NodeType = nodeType;
    }

    public int PostID { get; private set; }
    public string DisplayName { get; private set; }
    public string Url { get; private set; }
    public string Path { get; private set; }
    public AcmsMenuItemEnumerator Children { get; set; }
    public AcmsMenuItem Parent { get; set; }
    public bool ReadyToPublish { get; set; }
    public bool RequiresPublishing { get; set; }
    public Template.NodeTypes NodeType { get; set; }

    #region IHierarchyData Members

    public IHierarchicalEnumerable GetChildren()
    {
        return Children;
    }

    public IHierarchyData GetParent()
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public bool HasChildren
    {
        get { return Children != null && Children.Items.Count > 0; }
    }

    public object Item
    {
        get { return this; }
    }

    public string Type
    {
        get { return this.GetType().ToString(); }
    }

    #endregion
}
